package com.mlingdu.supercloudreader.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.bumptech.glide.Glide;
import com.mlingdu.supercloudreader.MainActivity;
import com.mlingdu.supercloudreader.R;
import com.mlingdu.supercloudreader.app.ConstantsImgUrl;
import com.mlingdu.supercloudreader.databinding.ActivityTransitionBinding;
import com.mlingdu.supercloudreader.utils.CommonUtils;
import com.mlingdu.supercloudreader.utils.PerfectClickListener;

import java.util.Random;

public class TransitionActivity extends AppCompatActivity {
	private ActivityTransitionBinding mBinding;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_transition);
		mBinding = DataBindingUtil.setContentView(this, R.layout.activity_transition);
		//先显示默认图，然后显示网络图
		mBinding.ivDefultPic.setImageDrawable(CommonUtils.getDrawable(R.drawable.img_transition_default));
		//取随机图片的序号
		int i = new Random().nextInt(ConstantsImgUrl.TRANSITION_URLS.length);
		Glide.with(this)
				.load(ConstantsImgUrl.TRANSITION_URLS[i])
				.placeholder(R.drawable.img_transition_default)
				.error(R.drawable.img_transition_default)
				.into(mBinding.ivPic);

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				mBinding.ivDefultPic.setVisibility(View.GONE);
			}
		}, 1500);
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				toMainActivity();
			}
		}, 3500);
		mBinding.tvJump.setOnClickListener(new PerfectClickListener() {
			@Override
			protected void onNoDoubleClick(View v) {
				toMainActivity();
			}
		});

	}
	private void toMainActivity(){
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
		finish();
	}
}
